package com.zxx.flowerstore.service.impl;

import com.zxx.flowerstore.service.MailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @ClassName MailServiceImpl
 * @Author Admin
 * @Date 2021/3/20 17:18
 * @Description MailServiceImpl
 * @Version 1.0
 */
@Service
public class MailServiceImpl implements MailService {

    @Value("${spring.mail.from}")
    private String from;

    @Autowired
    private JavaMailSender javaMailSender;

    private static final Logger logger = LoggerFactory.getLogger(MailServiceImpl.class);

    @Override
    public void sendValidationMail(String receiver, String code) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setTo(receiver);
        simpleMailMessage.setSubject("注册邮件");
        simpleMailMessage.setText("欢迎您注册玉田花圃,验证码为" + code);
        javaMailSender.send(simpleMailMessage);
    }
}
